import axios from 'axios';

//实例
const instance = axios.create({
    baseURL:'http://kumanxuan1.f3322.net:8360',
    timeout:5000
})

//请求前拦截
instance.interceptors.request.use(config=>{
        
        let token = localStorage.getItem('token');
        if(token){
            config.headers.common['X-Nideshop-Token']=token
        }
        return config
    },
    error=>{
        return Promise.reject(error)
    }
)

//响应拦截
instance.interceptors.response.use(
    result=>{
        if(result.data.errno===1000){
            localStorage.clear();
            window.location.reload()
        }
        return result.data
    },
    error=>{
        return Promise.reject(error)
    }
)

export default instance